package com.hzqy.service.industry.medical;

import com.alibaba.fastjson.JSONObject;
import com.hzqy.persistence.dao.industry.InformationSynDao;
import com.hzqy.web.vo.AlertDataInfoVo;
import com.hzqy.web.vo.InformationSynVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class InformationSynService {
    @Resource
    private InformationSynDao informationSynDao;
    protected final Logger LOG = LoggerFactory.getLogger(getClass());
    
    public int addInformationSyn(JSONObject request) {
        LOG.debug(request.toJSONString());
        InformationSynVo informationSynVo=new InformationSynVo();
        informationSynVo.setF_im_equ_id(request.get("telDeviceId")==null?"":request.get("telDeviceId").toString());
        informationSynVo.setF_im_data(request.get("data")==null?"":request.get("data").toString());
        informationSynVo.setF_im_equ_type(request.get("notifyType")==null?"":request.get("notifyType").toString());
        informationSynVo.setF_im_pushTime(request.get("time")==null?"":request.get("time").toString());
        informationSynVo.setF_im_syn_type(request.get("synType")==null?"":request.get("synType").toString());
        int i = informationSynDao.insertInformationSyn(informationSynVo);
        return i;
    }
    
    public List<InformationSynVo> selectInformationSyn(InformationSynVo informationSynVo) {
        List<InformationSynVo> informationSynVos=new ArrayList<>();
        List<InformationSynVo> informationSynVos1 = informationSynDao.selectInformationSyn(informationSynVo);
        informationSynVos.add(informationSynVos1.get(0));
        return informationSynVos;
    }
    
    public List<InformationSynVo> selectInformationSynByPage(InformationSynVo informationSynfoVo, int pageSize, int pageNum) {
        Map<String,Object> map=new HashMap<>();
        List<InformationSynVo> informationSynVos =null;
    
        List<InformationSynVo> informationSynVos1 = informationSynDao.selectInformationSyn(informationSynfoVo);
        int total=informationSynVos1.size();
        int pageTotal=0;
        if (total%pageSize==0){pageTotal=total/pageSize;}
        else {pageTotal=total/pageSize+1;}
        if (pageNum>pageTotal){pageNum=pageTotal;}
    
        map.put("pageNum",(pageNum-1)*pageSize);
        map.put("pageSize",pageSize);
        map.put("f_im_id",informationSynfoVo.getF_im_id());
        map.put("f_im_equ_id",informationSynfoVo.getF_im_equ_id());
        map.put("f_im_equ_type",informationSynfoVo.getF_im_equ_type());
        map.put("f_im_syn_type",informationSynfoVo.getF_im_syn_type());
        map.put("f_im_data",informationSynfoVo.getF_im_data());
        map.put("f_im_pushTime",informationSynfoVo.getF_im_pushTime());
        map.put("f_im_createTime",informationSynfoVo.getF_im_createTime());
        informationSynVos = informationSynDao.selectInformationSynByPage(map);
        return informationSynVos;
    }
}
